package com.compass.mobile.ui.viewModel

import androidx.lifecycle.MutableLiveData
import com.compass.mobile.framework.constant.BASE_ASSESSMENT
import com.compass.mobile.framework.utils.TipsToast
import com.compass.mobile.models.AssessmentBean
import com.compass.mobile.models.HealthDataWarp
import com.compass.mobile.models.HealthForDate
import com.compass.mobile.network.callback.IApiErrorCallback
import com.compass.mobile.network.manager.ApiManager
import com.compass.mobile.network.viewmodel.BaseViewModel
import com.google.gson.JsonObject

/**
 * Description： 健康档案--viewmodel
 * Date:2024/7/2 11:51
 */
class HealthRecordViewModel : BaseViewModel() {

    val healthLiveData = MutableLiveData<HealthDataWarp?>()
    val assessmentLiveData = MutableLiveData<AssessmentBean?>()
    val healthForDateLiveData = MutableLiveData<MutableList<HealthForDate>?>()


    fun getMeasurement(patientId: String?, measurementDate: String?) {

        val params = JsonObject().apply {
            addProperty("patientId", patientId)
            addProperty("measurementDate", measurementDate)

        }

        launchUIWithResult(responseBlock = {
            ApiManager.api.getMeasurement(params)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            healthForDateLiveData.value = it
        })
    }


    fun healthAssessment(age: String?, gender: String?,height:String?,weight:String?
                         ,blood_sugar:String?,blood_pressure_high:String?,blood_pressure_low:String?,uric_acid:String?) {

        val params = JsonObject().apply {
            addProperty("age", age)
            addProperty("gender", gender)
            addProperty("height", height)
            addProperty("weight", weight)
            addProperty("blood_sugar", blood_sugar)
            addProperty("blood_pressure_high", blood_pressure_high)
            addProperty("blood_pressure_low", blood_pressure_low)
            addProperty("uric_acid", uric_acid)
        }

        launchUIWithResult(responseBlock = {
            ApiManager.api.healthAssessment(BASE_ASSESSMENT,params)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            assessmentLiveData.value=it
        })
    }

    fun getHealthy(patientId: String?) {

        launchUIWithResult(responseBlock = {
            ApiManager.api.getHealthy(patientId)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            healthLiveData.value = it
        })
    }
}